package com.sqlcheck.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sqlcheck.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Optional;

@Mapper
public interface UserRepository extends BaseMapper<User> {

    @Select("SELECT * FROM users WHERE gitlab_id = #{gitlabId} AND deleted = 0")
    Optional<User> findByGitlabId(@Param("gitlabId") Long gitlabId);

    @Select("SELECT * FROM users WHERE username = #{username} AND deleted = 0")
    Optional<User> findByUsername(@Param("username") String username);

    @Select("SELECT * FROM users WHERE email = #{email} AND deleted = 0")
    Optional<User> findByEmail(@Param("email") String email);

    @Select("SELECT * FROM users WHERE employee_id = #{employeeId} AND deleted = 0")
    Optional<User> findByEmployeeId(@Param("employeeId") String employeeId);

    @Select("SELECT * FROM users WHERE employee_id = #{employeeId} AND password = #{password} AND deleted = 0")
    Optional<User> findByEmployeeIdAndPassword(@Param("employeeId") String employeeId, @Param("password") String password);
}